package com.one.consumer.user.ui;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.one.common.common.user.preserter.SettingPresenter;
import com.one.common.config.RouterPath;
import com.one.common.manager.RouterManager;
import com.one.common.utils.DataCleanManager;
import com.one.common.utils.SystemUtils;
import com.one.common.view.widget.HorizontalMenuItem;
import com.one.common.view.widget.MyTitleBar;
import com.one.consumer.BaseActivityC;
import com.one.consumer.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Author: zhulunjun
 * Time  : 2018/10/26 11:15
 * email : zhulunjun@qq.com
 * Describe : 设置页面
 **/
@Route(path = RouterPath.SETTING)
public class SettingActivity extends BaseActivityC<SettingPresenter> {
    @BindView(R.id.hmi_1)
    HorizontalMenuItem hmi1;
    @BindView(R.id.hmi_2)
    HorizontalMenuItem hmi2;
    @BindView(R.id.hmi_3)
    HorizontalMenuItem hmi3;
    @BindView(R.id.hmi_4)
    HorizontalMenuItem hmi4;
    @BindView(R.id.hmi_5)
    HorizontalMenuItem hmi5;
    @BindView(R.id.hmi_6)
    HorizontalMenuItem hmi6;
    @BindView(R.id.hmi_7)
    HorizontalMenuItem hmi7;
    @BindView(R.id.tv_btn_logout)
    TextView tvBtnLogout;

    @Override
    protected void initPresenter() {
        mPresenter = new SettingPresenter(this, this);
    }

    @Override
    public int getLayoutResId() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initTitle() {
        super.initTitle();
        getMyTitleBar().setMode(MyTitleBar.Mode.BACK_TITLE)
                .setTitleText("设置");
    }

    @Override
    public void initData() {
        super.initData();
        getCache();
    }

    /**
     * 修改登录密码
     */
    @OnClick(R.id.hmi_1)
    public void hmi_1() {
        RouterManager.getInstance().go(RouterPath.UPDATE_PWD);
    }

    /**
     * 绑定手机号
     */
    @OnClick(R.id.hmi_2)
    public void hmi_2() {
        RouterManager.getInstance().go(RouterPath.BIND_PHONE);
    }

    /**
     * 地址管理
     */
    @OnClick(R.id.hmi_3)
    public void hmi_3() {
        RouterManager.getInstance().go(RouterPath.SELECT_ADDRESS);
    }

    /**
     * 开票管理
     */
    @OnClick(R.id.hmi_4)
    public void hmi_4() {
        RouterManager.getInstance().go(RouterPath.INVOICE_MANAGER);
    }

    /**
     * 用户反馈
     */
    @OnClick(R.id.hmi_5)
    public void hmi_5() {
        RouterManager.getInstance().go(RouterPath.FEEDBACK);
    }

    /**
     * 关于我们
     */
    @OnClick(R.id.hmi_6)
    public void hmi_6() {
        RouterManager.getInstance().go(RouterPath.ABOUT);

    }

    /**
     * 清楚缓存
     */
    @OnClick(R.id.hmi_7)
    public void hmi_7() {
        DataCleanManager.clearAllCache(this);
        getCache();
    }

    /**
     * 退出登录
     */
    @OnClick(R.id.tv_btn_logout)
    public void logout() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("确定要退出登录？")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        mPresenter.logout();
                        dialog.dismiss();
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();
                    }
                }).show();
    }

    private void getCache() {
        // 获取缓存
        try {
            hmi7.getTvRightText().setText(DataCleanManager.getTotalCacheSize(this));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
